package org.swust.sysmonitorapp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.swust.sysmonitorapp.entity.DeviceStatus;
import org.swust.sysmonitorapp.entity.R;
import org.swust.sysmonitorapp.service.IDeviceStatusService;

import java.util.List;

/**
 * 设备状态控制器
 *
 * @since 2024-03-21
 */
@RestController
@RequestMapping("/device")
public class DeviceStatusController {

    @Autowired
    private IDeviceStatusService deviceStatusService;

    /**
     * 获取所有设备状态
     *
     * @return 设备状态列表
     */
    @GetMapping("/list")
    public R<List<DeviceStatus>> getAllDeviceStatus() {
        return R.ok(deviceStatusService.getAllDeviceStatus());
    }

    /**
     * 根据设备ID查询设备状态
     *
     * @param deviceId 设备ID
     * @return 设备状态
     */
    @GetMapping("/{deviceId}")
    public R<DeviceStatus> getDeviceStatus(@PathVariable String deviceId) {
        return R.ok(deviceStatusService.getById(deviceId));
    }

    /**
     * 更新设备状态
     *
     * @param deviceId 设备ID
     * @param status 状态
     * @return 操作结果
     */
    @PutMapping("/{deviceId}")
    public R<Boolean> updateDeviceStatus(
            @PathVariable String deviceId,
            @RequestParam String status) {
        return R.ok(deviceStatusService.updateDeviceStatus(deviceId, status));
    }
}